//package com.itheima.advice;
//
//import com.itheima.mapper.LoginMapper;
//import com.itheima.pojo.EmpDto;
//import com.itheima.pojo.EmpLoginLog;
//import com.itheima.pojo.LoginInfo;
//import com.itheima.service.EmpService;
//import com.itheima.utils.TliasException;
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import java.time.LocalDateTime;
//
//@Aspect
//@Component
//@Slf4j
//public class EmpAdvice {
//    @Autowired
//    private EmpService empService;
//    @Around("execution(* com.itheima.service.impl.EmpServiceImpl.findLoginInfo(..))")
//    public Object abc(ProceedingJoinPoint pjp) throws Throwable {
//        EmpLoginLog empLoginLog = new EmpLoginLog();
//        empLoginLog.setLoginTime(LocalDateTime.now());
//        long begin =System.currentTimeMillis();
//
//        Object[] args = pjp.getArgs();
//        EmpDto empDto = null;
//
//        if (args != null && args.length > 0 ) {
//            empDto = (EmpDto) args[0];
//        }
//        Object result = null;
//        empLoginLog.setUsername( empDto.getUsername());
//        empLoginLog.setPassword(empDto.getPassword());
//        try {
//            result = pjp.proceed();
//            empLoginLog.setIsSuccess((short) 1);
//            LoginInfo loginInfo =(LoginInfo) result;
//            empLoginLog.setJwt(loginInfo.getToken());
//            long end =System.currentTimeMillis();
//            long cost =end -begin;
//            empLoginLog.setCostTime(cost);
//            empService.insertlog(empLoginLog);
//            return result;
//        }catch (Exception e){
//            empLoginLog.setIsSuccess((short)0);
//            empLoginLog.setJwt(null);
//            long end =System.currentTimeMillis();
//            long cost =end -begin;
//            empLoginLog.setCostTime(cost);
//            loginMapper.insertlog(empLoginLog);
//            throw new TliasException("用户名或密码错误");
//        }
//    }
//}
